public class Solution121 {
    public int maxProfit(int[] prices) {
        int min=prices[0];
        int ans=0;
        for (int i=1;i<prices.length;i++){
            if (prices[i]-min>ans){
                ans=prices[i]-min;
            }
            min=Math.min(min,prices[i]);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution121().maxProfit(new int[]{7,1,5,3,6,4}));
    }
}
